package jsr292.java.lang.invoke;

import jsr292.weaver.Debug;
import jsr292.weaver.opt.OptimizerContext;
import jsr292.weaver.opt.OptimizerSnippets;
import jsr292.weaver.opt.OptimizerVarAllocator;

class MHConvertDelegator extends MethodHandle {
    private final MethodHandle mh;
    
    public MHConvertDelegator(MethodHandle mh, MethodType methodType) {
        super(methodType);
        this.mh = mh;
    }
    
    @Override
    public Object $invoke$() throws Throwable {
        return mh.$invoke$();
    }
    
    @Override
    public Object $invoke$(Object o1) throws Throwable {
        return mh.$invoke$(o1);
    }

    @Override
    public Object $invoke$(Object o1, Object o2) throws Throwable {
        return mh.$invoke$(o1, o2);
    }
    
    @Override
    public Object $invoke$(Object o1, Object o2, Object o3) throws Throwable {
        return mh.$invoke$(o1, o2, o3);
    }
    
    @Override
    public Object $invoke$(Object o1, Object o2, Object o3, Object o4) throws Throwable {
        return mh.$invoke$(o1, o2, o3, o4);
    }

    @Override
    public Object $invoke$(Object o1, Object o2, Object o3, Object o4, Object o5) throws Throwable {
        return mh.$invoke$(o1, o2, o3, o4, o5);
    }
    
    @Override
    public Object $invoke$(Object o1, Object o2, Object o3, Object o4, Object o5, Object o6) throws Throwable {
        return mh.$invoke$(o1, o2, o3, o4, o5, o6);
    }

    @Override
    public Object $invoke$(Object o1, Object o2, Object o3, Object o4, Object o5, Object o6, Object o7) throws Throwable {
        return mh.$invoke$(o1, o2, o3, o4, o5, o6, o7);
    }

    @Override
    public Object $invoke$(Object... rest) throws Throwable {
        return mh.$invoke$(rest);
    }    
    

    @Override
    public boolean isWeavable(Class<?> classBeingRedefined) {
        return mh.isWeavable(classBeingRedefined);
    }
    @Override
    public void weave(OptimizerContext context, OptimizerVarAllocator allocator) {
        if (Debug.DEBUG) {
            Debug.checkAllocator(allocator, this);
        }
        
        OptimizerSnippets.convert(context, allocator, mh, type());
    }
}
